﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class WebForm_ManageUser_ucQueryUser : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //如果是環保局人員(2),則 MyOrganizationID 改成台北縣政府(15)
            ObjectDataSource_Organization.SelectParameters["MyOrganizationID"].DefaultValue = (CS_clsAuth.MyOrganizationID == "2" ? "15" : CS_clsAuth.MyOrganizationID);
            ObjectDataSource_User.SelectParameters["MyOrganizationID"].DefaultValue = (CS_clsAuth.MyOrganizationID == "2" ? "15" : CS_clsAuth.MyOrganizationID);        
        }


    }

    //所屬單位多個時，加上"全部"
    protected void ddlOrganizationID_DataBound(object sender, EventArgs e)
    {
        if (ddlOrganizationID.Items.Count > 1)
        {
            ddlOrganizationID.Items.Insert(0, new ListItem("全部", "0"));
        }
    }

    //查詢
    protected void btnQuery_Click(object sender, EventArgs e)
    {
        ObjectDataSource_User.SelectParameters["EmployeeID"].DefaultValue = txtEmployeeID.Text;
        ObjectDataSource_User.SelectParameters["EmployeeName"].DefaultValue = txtEmployeeName.Text;
        ObjectDataSource_User.SelectParameters["OrganizationID"].DefaultValue = ddlOrganizationID.SelectedValue;
        TGridView1.DataBind();
    }


    public delegate void GoEditDelegate(object sender, EventArgs e);
    public event GoEditDelegate GoEdit;

    //編輯
    protected void TGridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (GoEdit != null)
        {
            GoEdit(this, e);
        }
    }

    public delegate void GoDeleteDelegate(object sender, EventArgs e);
    public event GoDeleteDelegate GoDelete;
    //刪除
    protected void lbtnDelete_Click(object sender, EventArgs e)
    {
        if (GoDelete != null)
        {
            GoDelete(this, e);
        }
    }

    //設定角色
    protected void lbtnSetup_Click(object sender, EventArgs e)
    {
        TGridView1.EditIndex = -1;
        OpenManageUserRoleMapping1.EmployeeID = TGridView1.DataKeys[((GridViewRow)((LinkButton)sender).NamingContainer).RowIndex].Value.ToString();
        OpenManageUserRoleMapping1.InitDataAndShow();
    }


}


public partial class WebForm_ManageUser_ucQueryUser 
{
    public void InitData()
    {
        ObjectDataSource_User.SelectParameters["OrganizationID"].DefaultValue = "0";
        TGridView1.DataSourceID = this.ObjectDataSource_User.ID;
        TGridView1.DataBind();
    }

    protected bool BooleanConverter(object strTMP)
    {
        return (strTMP.ToString() == "Y" ? true : false);
    }


    #region Property

    public string SelectedID
    {
        get
        {
            if (TGridView1.SelectedRow == null)
            {
                return "0";            
            }
            else
            {
                return TGridView1.DataKeys[TGridView1.SelectedIndex].Value.ToString();
            
            }
        }
 
    }

    #endregion

}

